#coding=utf-8

from socket import *
import time

host = '192.168.0.19'
port = 12345
BUF_SIZE = 1024
addr = (host,port)

client_sock = socket(AF_INET,SOCK_STREAM)
client_sock.connect(addr)

while True:
	data = time.ctime() + ' hello'
	if data == '':
		if not data:
			print 'empty string'
	elif data == 'exit':
		break
	elif data == None:
		print '发送空数据'
	len = client_sock.send(data)
	print('send: %s len: %d'%(data,len))
	try:
		data = client_sock.recv(BUF_SIZE)
	except:
		print('keyboard exception')
		continue
	if not data:
		print('exit')
		break
	print('recv :',data)
	sleep(3)

client_sock.close()
